<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>管理后台-修改信息</title>
    <header th:replace="header::html"/>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <input type="hidden" name="id" th:value="${test.id}" />
				<div class="layui-form-item">
					<label for="field1" class="layui-form-label">
						<span class="x-red">*</span>field1
					</label>
					<div class="layui-input-inline">
						<input type="text" id="field1" name="field1" th:value="${test.field1}" lay-verify="required" class="layui-input">
					</div>
					<div class="layui-form-mid layui-word-aux">
						<span class="x-red">*</span>测试字段1
					</div>
				</div>
				<div class="layui-form-item">
					<label for="field2" class="layui-form-label">
						<span class="x-red">*</span>field2
					</label>
					<div class="layui-input-inline">
						<input type="text" id="field2" name="field2" th:value="${test.field2}" lay-verify="required" class="layui-input">
					</div>
					<div class="layui-form-mid layui-word-aux">
						<span class="x-red">*</span>测试字段2
					</div>
				</div>
				<div class="layui-form-item">
					<label for="field3" class="layui-form-label">
						<span class="x-red">*</span>field3
					</label>
					<div class="layui-input-inline">
						<input type="text" id="field3" name="field3" th:value="${test.field3}" lay-verify="required" class="layui-input">
					</div>
					<div class="layui-form-mid layui-word-aux">
						<span class="x-red">*</span>测试字段3
					</div>
				</div>
				<div class="layui-form-item">
					<label for="field4" class="layui-form-label">
						<span class="x-red">*</span>field4
					</label>
					<div class="layui-input-inline">
						<input type="text" id="field4" name="field4" th:value="${test.field4}" lay-verify="required" class="layui-input">
					</div>
					<div class="layui-form-mid layui-word-aux">
						<span class="x-red">*</span>测试字段4
					</div>
				</div>
				<div class="layui-form-item">
					<label for="field5" class="layui-form-label">
						<span class="x-red">*</span>field5
					</label>
					<div class="layui-input-inline">
						<input type="text" id="field5" name="field5" th:value="${test.field5}" lay-verify="required" class="layui-input">
					</div>
					<div class="layui-form-mid layui-word-aux">
						<span class="x-red">*</span>测试字段5
					</div>
				</div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="submit" class="layui-btn" lay-filter="edit" lay-submit="" permission="test:edit">修改</button>
                        <button class="layui-btn layui-btn-primary" onclick="xadmin.close();">取消</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
	<script type="text/javascript">
		layui.use(['form', 'layer'], function() {
		    var form = layui.form,
                layer = layui.layer;

			// 权限校验
			checkPermissoin();

            // 自定义验证规则
            form.verify({

            });

            // 监听提交
            form.on('submit(edit)', function (data) {
                // 发异步请求，修改信息
                $.ajax({
                    url: '/test/edit',
                    type: 'PUT',
                    data: data.field,
                    dataType: 'json',
                    beforeSend: function() {
                        layer.load();
                    },
                    success: function (res) {
                        if (res.httpCode != 200 || res.retCode != 0) {
                            layer.alert(res.retMsg);
                        } else {
                            layer.alert("修改成功", {icon: 6}, function () {
                                // 关闭当前frame
                                xadmin.close();
                                // 对父窗口进行刷新
                                xadmin.father_reload();
                            });
                        }
                    }
                });
                layer.closeAll();
                return false;
            });
		});
	</script>
</body>
</html>